home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / gnu / gnulib / dkbtrace / pbmplus / source / pbm / pbmtopi3.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-06  |  2.6 KB  |  127 lines

  1. /* pbmtopi3.c - read a portable bitmap and produce a Atari Degas .pi3 file
  2. **
  3. ** Module created from other pbmplus tools by David Beckemeyer.
  4. **
  5. ** Copyright (C) 1988 by David Beckemeyer and Jef Poskanzer.
  6. **
  7. ** Permission to use, copy, modify, and distribute this software and its
  8. ** documentation for any purpose and without fee is hereby granted, provided
  9. ** that the above copyright notice appear in all copies and that both that
  10. ** copyright notice and this permission notice appear in supporting
  11. ** documentation.  This software is provided "as is" without express or
  12. ** implied warranty.
  13. */
  14.  
  15. #include <stdio.h>
  16. #include "pbm.h"
  17.  
  18. static void putinit ARGS(( void ));
  19. static void putbit ARGS(( bit b ));
  20. static void putrest ARGS(( void ));
  21. static void putitem ARGS(( void ));
  22.  
  23. void
  24. main( argc, argv )
  25.     int argc;
  26.     char* argv[];
  27.     {
  28.     FILE* ifp;
  29.     bit* bitrow;
  30.     register bit* bP;
  31.     int rows, cols, format, padright, row, col;
  32.  
  33.     pbm_init( &argc, argv );
  34.  
  35.     if ( argc > 2 )
  36.     pm_usage( "[pbmfile]" );
  37.  
  38.     if ( argc == 2 )
  39.     ifp = pm_openr( argv[1] );
  40.     else
  41.     ifp = stdin;
  42.  
  43.     pbm_readpbminit( ifp, &cols, &rows, &format );
  44.     if (cols > 640)
  45.     cols = 640;
  46.     if (rows > 400)
  47.     rows = 400;
  48.     bitrow = pbm_allocrow( cols );
  49.     
  50.     /* Compute padding to round cols up to 640 */
  51.     padright = 640 - cols;
  52.  
  53.     putinit( );
  54.     for ( row = 0; row < rows; ++row )
  55.     {
  56.     pbm_readpbmrow( ifp, bitrow, cols, format );
  57.         for ( col = 0, bP = bitrow; col < cols; ++col, ++bP )
  58.         putbit( *bP );
  59.     for ( col = 0; col < padright; ++col )
  60.         putbit( 0 );
  61.         }
  62.     while (row++ < 400)
  63.     for ( col = 0; col < 640; ++col)
  64.         putbit( 0 );
  65.  
  66.     pm_close( ifp );
  67.  
  68.     putrest( );
  69.  
  70.     pm_close (stdout);
  71.  
  72.     exit( 0 );
  73.     }
  74.  
  75. static short item;
  76. static short bitsperitem, bitshift;
  77.  
  78. static void
  79. putinit( )
  80.     {
  81.     struct degasHDR {
  82.     short res;
  83.     short pal[16];
  84.     } hdr;
  85.  
  86.     hdr.res = 2;
  87.     hdr.pal[0] = 0x0777;
  88.     hdr.pal[1] = 0x0700;
  89.     fwrite( &hdr, sizeof(hdr), 1, stdout );
  90.     item = 0;
  91.     bitsperitem = 0;
  92.     bitshift = 15;
  93.     }
  94.  
  95. #if __STDC__
  96. static void
  97. putbit( bit b )
  98. #else /*__STDC__*/
  99. static void
  100. putbit( b )
  101.     bit b;
  102. #endif /*__STDC__*/
  103.     {
  104.     if ( bitsperitem == 16 )
  105.     putitem( );
  106.     ++bitsperitem;
  107.     if ( b == PBM_BLACK )
  108.     item += 1 << bitshift;
  109.     --bitshift;
  110.     }
  111.  
  112. static void
  113. putrest( )
  114.     {
  115.     if ( bitsperitem > 0 )
  116.     putitem( );
  117.     }
  118.  
  119. static void
  120. putitem( )
  121.     {
  122.     fwrite( &item, sizeof(item), 1, stdout );
  123.     item = 0;
  124.     bitsperitem = 0;
  125.     bitshift = 15;
  126.     }
  127.